package com.smarttest.main

import android.arch.lifecycle.ViewModelProviders
import com.smarttest.base.ViewModelFactory
import com.smarttest.dagger.di.ActivityScoped
import com.smarttest.net.ApiService
import dagger.Module
import dagger.Provides

@Module
abstract class MainModule {
//      fragment注册需要在虚函数里面
//    @FragmentScoped
//    @ContributesAndroidInjector
//    abstract fun desktopFragment(): MainBomFragment



    @Module
    companion object {
        @Provides
        @JvmStatic
        @ActivityScoped
        fun provideRepository(apiService: ApiService): MainRepository {
            return MainRepository( apiService)
        }


        @Provides
        @JvmStatic
        @ActivityScoped
        fun provideMainViewModel(activity: MainActivity, repository: MainRepository): MainViewModel {
            val factory = ViewModelFactory(repository)
            return ViewModelProviders.of(activity, factory).get(MainViewModel::class.java)
        }
    }
}
